package com.geostar.constructionland.common.entity.response;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;

public class ExtjsResponse<T> implements Serializable {
    private boolean success;
    private String message;
    private T data;

    private ExtjsResponse(boolean success) {
        this.success = success;
    }

    public ExtjsResponse(boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    public ExtjsResponse(boolean success, T data) {
        this.success = success;
        this.data = data;
    }

    private ExtjsResponse(boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;

    }

    @JsonIgnore
    public boolean isSuccess() {
        return this.success == ExtjsCode.SUCCESS.getSuccess();
    }

    public boolean getSuccess() {
        return success;
    }

    public T getData() {
        return data;
    }

    public String getMessage() {
        return message;
    }

    public static <T> ExtjsResponse<T> createBySuccess() {
        return new ExtjsResponse<T>(ExtjsCode.SUCCESS.getSuccess(), ResponseCode.SUCCESS.getDesc());
    }

    public static <T> ExtjsResponse<T> createBySuccessMessage(String message) {
        return new ExtjsResponse<T>(ExtjsCode.SUCCESS.getSuccess(), message);
    }

    public static <T> ExtjsResponse<T> createBySuccess(T data) {
        return new ExtjsResponse<T>(ExtjsCode.SUCCESS.getSuccess(), ResponseCode.SUCCESS.getDesc(), data);
    }

    public static <T> ExtjsResponse<T> createBySuccess(String message, T data) {
        return new ExtjsResponse<T>(ExtjsCode.SUCCESS.getSuccess(), message, data);
    }

    public static <T> ExtjsResponse<T> createByError() {
        return new ExtjsResponse<T>(ExtjsCode.SUCCESS.getSuccess(), ResponseCode.ERROR.getDesc());
    }

    public static <T> ExtjsResponse<T> createByErrorMessage(String errorMessage) {
        return new ExtjsResponse<T>(ExtjsCode.SUCCESS.getSuccess(), errorMessage);
    }

    public static <T> ExtjsResponse<T> createByErrorCodeMessage(boolean errorCode, String errorMessage) {
        return new ExtjsResponse<T>(errorCode, errorMessage);
    }
}